package com.dd.web.base.entity.view;

import com.alibaba.fastjson.JSONObject;
import com.dd.web.base.entity.data.UmsAdmin;
import com.dd.web.base.entity.data.UmsMenu;
import com.dd.web.base.entity.data.UmsRole;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Setter
@Getter
@ApiModel(value ="用户详细信息",description = "")
public class AdminUserDetails {
    @ApiModelProperty(value="用户基础信息对象",notes="")
    private UmsAdmin umsAdmin;
    @ApiModelProperty(value = "用户资源列表",notes = "")
    private List<UmsMenu> menuList;

    @ApiModelProperty("用户角色集合")
    private List<UmsRole> roleList;

    public AdminUserDetails(UmsAdmin umsAdmin,List<UmsMenu> menuList) {
        this.umsAdmin = umsAdmin;
        this.menuList = menuList;
    }

    public List<GrantedAuthority> getAuthorityList(){
        List<GrantedAuthority> authorityList = new ArrayList<>();
        this.getRoleList().forEach(role -> authorityList.add(new SimpleGrantedAuthority(role.getId()+"")));
        log.info("用户{}角色集合{}",JSONObject.toJSON(this.umsAdmin),JSONObject.toJSONString(authorityList));
        return authorityList;
    }


}